package com.sanhuo.idms.dao;

import com.sanhuo.idms.bo.StudentPageBO;
import com.sanhuo.idms.dao.provider.StudentProvider;
import com.sanhuo.idms.entity.Student;
import com.sanhuo.idms.vo.StudentPageVO;
import com.sanhuo.idms.vo.StudentVO;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.annotation.*;
import com.sanhuo.triild.page.Page;
import com.sanhuo.triild.page.PageSearch;

import java.util.List;

@Mapper
public interface StudentMapper extends BaseMapper<Student> {

    @SelectProvider(type = StudentProvider.class, method = "findStudentByBO")
    List<Student> findAll(StudentPageBO pageBO);

//    @SelectProvider(type = StudentProvider.class, method = "findStudentByBO")
//    Page<Student> listAll(StudentPageBO pageBO, PageSearch pageSearch);

    @SelectProvider(type = StudentProvider.class, method = "listAll")
    Page<StudentPageVO> listAll(StudentPageBO pageBO, PageSearch pageSearch);

    @Select("select count(*) from student where clasId = #{clasId}")
    Integer countByClasId(String clasId);
//    @Select("select * from student where id = #{id}")
//    Student findById(String id);

//    @UpdateProvider(type = StudentProvider.class, method = "update")
//    void update(Student student);
//
//    @InsertProvider(type = StudentProvider.class, method = "insert")
//    void save(Student student);

    @Select("select s.name name,s.id id,bunkNum from dorm d,student s where d.id = s.dormId and d.id = #{dormId}")
    List<Student> findByDormId(String dormId);

    @Select("select u.id id,u.name name,gender,phone,email,qq,cl.name college ,t.num tungNum,r.num roomNum,s.bunkNum," +
            "cl.id collegeId,c.id clasId,concat(clasGrade,cl.id,clasNum) clas,d.id dormId," +
            " concat(t.num,\"-\",r.num) dorm from user u join student s join dorm d join tung " +
            "   t join room r join clas c join college cl " +
            " on u.id = s.id and s.dormId = d.id and d.tungId = t.id and d.roomId = r.id and s.clasId = c.id and c.collegeId = cl.id" +
            "   where u.id= #{id}")
    StudentVO detail(String id);

}
